package com.bawei.module_publish.openlive.model.repository

import com.bawei.lib_net.RetrofitFactory
import com.bawei.module_publish.openlive.model.api.LiveApi
import com.bawei.module_publish.openlive.model.entity.OpenLiveBody
import com.bawei.module_publish.openlive.model.entity.SendAdInfoBody
import com.bawei.module_publish.openlive.model.entity.SendPacketBody
import com.bawei.module_publish.openlive.model.entity.SquareGoodsBody
import com.bawei.module_publish.openlive.model.entity.TopCarBody
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn

class LiveRepository {
    val api: LiveApi
    init {
        api= RetrofitFactory.getRetrofitFactory().create(LiveApi::class.java)
    }
    //开启直播
    fun openLive(body: OpenLiveBody) = flow {
        emit(api.openLive(body))
    }.flowOn(Dispatchers.IO)
    //发送红包
    fun sendRedPacket(body: SendPacketBody) = flow {
        emit(api.sendRedPacket(body))
    }.flowOn(Dispatchers.IO)
    //获取在线人数
    fun getOnlineNum(roomId:String) = flow {
        emit(api.getOnlineNum(roomId))
    }.flowOn(Dispatchers.IO)
    //删除直播间
    fun deleteLiveRoom(roomId:String) = flow {
        emit(api.deleteLiveRoom(roomId))
    }.flowOn(Dispatchers.IO)
    //我的橱窗
    fun myShowcase() = flow {
        emit(api.myShowcase())
    }.flowOn(Dispatchers.IO)
    //上车商品
    fun topCar(body: TopCarBody) = flow {
        emit(api.topCar(body))
    }.flowOn(Dispatchers.IO)
    //直播间商品
    fun liveRoomGoods(roomId:String) = flow {
        emit(api.liveRoomGoods(roomId))
    }.flowOn(Dispatchers.IO)
    //正在介绍的商品
    fun explainGoods(body: TopCarBody) = flow {
        emit(api.explainGoods(body))
    }.flowOn(Dispatchers.IO)
    //商品广场
    fun chooseProductSquare(body: SquareGoodsBody) = flow {
        emit(api.chooseProductSquare(body))
    }.flowOn(Dispatchers.IO)
    //添加或取消商品
    fun addOrCancelShowcase(goodsId: Int) = flow {
        emit(api.addOrCancelShowcase(goodsId))
    }.flowOn(Dispatchers.IO)
    //广告信息
    fun adInfo(body: SendAdInfoBody) = flow {
        emit(api.adInfo(body))
    }.flowOn(Dispatchers.IO)
}